package com.dominator.repository;

import javax.annotation.Resource;

import com.dominator.mybatis.dao.T_smsDao;
import com.dominator.mybatis.dao.T_smsPO;
import com.dominator.utils.dao.JdbcHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.dominFramework.core.dao.SqlDao;
import com.dominFramework.core.typewrap.Dto;
import com.dominFramework.core.typewrap.Dtos;

@Repository
public class DaoSms {

	@Autowired
	SqlDao sqlDao;
	
	@Autowired
	T_smsDao smsDao;
	
	
	@Resource
	JdbcHelper jh;
	
	/**
	 * 添加
	 * 
	 * @param record
	 * @return
	 */
	public Integer insertSelective(T_smsPO record) {
		return smsDao.insert(record);
	}

	/**
	 * 删除
	 * 
	 * @param
	 * @return
	 */
	public Integer deleteByPrimaryKey(String id) {
		return smsDao.deleteByKey(id);
	}

	/**
	 * 修改
	 * 
	 * @param record
	 * @return
	 */
	public Integer updateByPrimaryKey(T_smsPO record) {
		return smsDao.updateByKey(record);
	}


	/**
	 * 查询单条记录
	 * 
	 * @param id
	 * @return
	 */
	public T_smsPO selectByPrimaryKey(String id) {
		T_smsPO row = smsDao.selectByKey(id);
		return row;
	}

    /**
     * 通过验证码和类型查询
     * @param code
     * @param stype
     * @return
     */
	public T_smsPO selectByCodeStype(String code,String stype){
		Dto qDto=Dtos.newDto();
		qDto.put("code", code);
		qDto.put("stype", stype);
		T_smsPO row = (T_smsPO) sqlDao.selectOne("Sms.selectByCodeStype", qDto);
		return row;
	}
	
	/**
	 * 单号码发送次数
	 * @param phoneNum
	 * @return
	 */
	public Integer countByPhoneNum(String phoneNum){
		StringBuffer sb=new StringBuffer();
		sb.append(" select count(1) from t_sms where mobile ='"+phoneNum+"'");
		sb.append(" and to_days(create_time) = to_days(now())");
		sb.append(" and stype<=3");
		return jh.count(sb.toString(), null);
	}
	
	
}
